const app = getApp();
Page({
  data: {
    server:app.globalData.server,
    api:app.globalData.api,
    memberAdList:[
      {path:"../../assets/img/data/member-ad4.jpg"},
      {path:"../../assets/img/data/member-ad5.jpg"},
      {path:"../../assets/img/data/member-ad6.jpg"},
    ],
    isLogin:false,
    rules:[
      "1.快去分享商品收益吧!",
      "2.尊敬的用户，您登录之后可对商品进行分享，如果通过您的分享生成新的订单，那么您就可获得这一单对应的佣金;",
      "3.无门槛成为分销商，只要您注册登陆，您就是一级分销商;",
      "4.如果通过您分享成功的订单超过某个数量，那您可自动升级为二级分销商;",
      "5.二级分销商获取的佣金比例会相对一级分销商会多一点喔!",
      "6.以此类推，您分享成功的订单越多，您的等级就会越高，相应的佣金比例也会提高呢!",
      "7.准备好了吗，是时候表演真正的技术了!"
    ],
    promotion:{
      tableThemes:{},
      tableItems:[]
    },
  },
  onLoad() {
    //获取等级表promotion
    this.getLevelRule()
  },
  onShow(){
    let that = this;
    my.getStorage({
      key: 'userInfo',
      success: function(res) {
        that.setData({
          isLogin:res.data?true:false
        })
      }
    });
  },
  getLevelRule(){
    let that = this;
    my.request({
      url:this.data.api+'/commission/rule',
      method: 'get',
      headers:{
        'content-type':'application/json',
        'token':this.data.token
      },
      dataType: 'json',
      success: function(res) {
        console.log(res)
        if(res.data.errCode==0){
          let list = res.data.result.map((val,index,arr)=>{
            return {
              grade:val.level,
              order:val.order_num,
              proportion:val.proportion
            }
          })
          that.setData({
             promotion:{
              tableThemes:{'grade':'等级','order':'订单数量','proportion':'佣金比例'},
              tableItems:list
            },
          })
        }
      }
    });
  }
});
